Add Spring Context Accessor for Static Access to Tenant Properties #271
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new utility class,
SpringContextAccessor
, which provides static access to the Spring application context. This allows for the retrieval of beans, such as tenant properties, in a static manner. Additionally, a factory method has been added toOkapiRestTemplate
to facilitate its creation and configuration using a builder pattern.Key Changes:
New Utility Class:
SpringContextAccessor
ApplicationContextAware
to set the application context automatically when the Spring container starts.getBean(Class<T> beanClass)
to retrieve beans from the application context.Factory Method in
OkapiRestTemplate
build()
for creating and configuringOkapiRestTemplate
instances using a fluent API.Unit Tests
SpringContextAccessorTest
to ensure the correct retrieval of tenant properties bean.SpringBootTest
with mock web environment for testing.Rationale:
Static Access to Beans: The
SpringContextAccessor
allows for easy and static access to Spring-managed beans, which is particularly useful for accessing tenant-specific properties across different parts of the application.Fluent API for
OkapiRestTemplate
: The factory method enhances the usability ofOkapiRestTemplate
by providing a clear and concise way to instantiate and configure it.Preventing Deserialization: Making the constructor of
OkapiRestTemplate
private prevents direct instantiation and deserialization, which enhances security by ensuring that instances are only created through the controlled factory method.Improved Test Coverage: The added tests ensure that the new functionality works as expected and integrates well with the existing application context.
Additional Changes: